﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="~/plugins/mzui/js/mzui.min.js"></script>
    <link href="~/plugins/mzui/css/mzui.min.css" rel="stylesheet" />
    <script src="~/js/jquery.js"></script>
    <title>个人中心</title>
    <style>
        .profile-haeder {
            position: relative;
            overflow: hidden;
            min-height: 8rem
        }

            .profile-haeder > .back {
                top: -2rem;
                left: -2rem;
                right: -2rem;
                bottom: -2rem;
                background-position: center;
                background-size: cover
            }

            .profile-haeder > .front {
                background: rgba(0,0,0,.1);
                text-align: center;
                padding: 1.5rem
            }
    </style>
</head>
<body class="with-nav-bottom">
    <div>
        <div class="heading">
            <div class="title"><strong>修改密码</strong></div>
            <nav class="nav"><a data-dismiss="display"><i class="icon-remove muted"></i></a></nav>
        </div>
        <section class="section">
            <div class="box">
                <div class="control has-error">
                    <label for="pwd">当前密码</label>
                    <input id="pwd" name="pwd" type="password" class="input" placeholder="请输入当前使用的密码">
                    <p id="mm" class="help-text"></p>
                </div>
                <div class="control has-error">
                    <label for="newpwd">新密码</label>
                    <input id="newpwd" name="newpwd" type="password" class="input" placeholder="请使用不少于 6 个字符的密码">
                    <p id="xmm" class="help-text"></p>
                </div>
                <div class="control">
                    <button type="button" id="pwdok" class="btn block primary" onclick="return shoppwd();">提交</button>
                </div>
                <div class="red box fade in hidden" id="msg" style="text-align:center;"></div>
            </div>
        </section>
    </div>
    <script>
        function shoppwd() {
            if (document.getElementById("pwd").value.length < 6) {
                document.getElementById("mm").innerHTML = "密码最少修6位";
                return false;
            }
            else {
                document.getElementById("mm").innerHTML = "";
            }
            if (document.getElementById("newpwd").value.length < 6) {
                document.getElementById("xmm").innerHTML = "密码最少修6位";
                return false;
            }
            if (document.getElementById("pwd").value == document.getElementById("newpwd").value) {
                document.getElementById("xmm").innerHTML = "新密码不能和原密码一样";
                return false;
            }
            else {
                document.getElementById("xmm").innerHTML = "";
            }
            $.ajax({
                url: "/ajax/api.ashx",
                data: "ff=shoppwd&pwd=" + document.getElementById("pwd").value + "&newpwd=" + document.getElementById("newpwd").value + "&Cache=" + Math.random(),
                type: "post",
                cache: false,
                timeout: 8000,
                dataType: "json",
                ContentType: "application/json; charset=utf-8",
                async: false,//一定要是同步请求，否则会跳转；（ajax默认是异步的）
                error: function () { document.getElementById("pwdok").innerText = "更新"; document.getElementById("pwdok").disabled = ""; alert("AJAX Error");  },
                beforeSend: function () { document.getElementById("pwdok").innerText = "提交中..."; document.getElementById("pwdok").disabled = true; },
                success: function (data) {
                    console.log(data);
                    document.getElementById("pwdok").disabled = "";
                    if (data.result == 200) {
                        $("#msg").removeClass("hidden").html("修改密码成功,请记住呢的新密码!");
                    }
                    else {
                        $("#msg").removeClass("hidden").html("更新失败:" + data.data);
                    }
                },
            });
        }
    </script>
</body>
</html>
